<?php
/**
 * MatchDart! is a darts event ranking table component for joomla
 * 
 * @version		2.0.1 | $Id: seasonselect.php 93 2009-08-28 10:56:02Z mwi.nor $
 * @package		MatchDart!
 * @subpackage	Admin
 * @copyright	Copyright (C) 2005 - 2009 Marco Wilde. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * @author		Marco Wilde, <mailto://info@matchdart.de>
 * @link		http://www.matchdart.de
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

/**
 * Renders Season select box
 *
 * @package 	MatchDart
 * @subpackage	Admin
 */
class JElementSeasonselect extends JElement
{
    /**
     * Element name
     *
     * @access	protected
     * @var	string
     */
    var	$_name = 'Seasonselect';
 
    function fetchElement($name, $value, &$node, $control_name)
    {
    	$db =& JFactory::getDBO();
    	
    	$query = 'SELECT SeasonID FROM #__md_seasons WHERE SeasonDefault = 1';
   		$db->setQuery( $query );
        $d_seasonid = $db->loadResult();
        
    	$currentValue = ( $value != 0 ? $value : $d_seasonid );
        
        $query = 'SELECT * FROM #__md_seasons WHERE SeasonPublish = 1 ORDER BY SeasonName DESC';
   		$db->setQuery( $query );
        $seasons = $db->loadObjectList();
            
        $k=1;
        //FIXME: 'foreach' --> error if events table empty
        foreach ($seasons as $season){
        	$option[$k] = JHTML::_('select.option', $season->SeasonID, $season->SeasonName);
        	$k++;
        }
        
        $selectName = $control_name."[".$name."]";
        
        $seasonSelect = JHTML::_('select.genericlist', $option, $selectName, null, 'value', 'text', $currentValue, $control_name.$name);
    	
        return $seasonSelect;
        
     }//function
 
}//class